﻿$(function () {
    laydate.render({ elem: '#dtDiseaseTime', type: 'datetime' });
    laydate.render({ elem: '#txtArriveTime', type: 'datetime' });
    laydate.render({ elem: '#txtArriveBypass', type: 'datetime' });
    laydate.render({ elem: '#txtReceiveTime', type: 'datetime' });
    laydate.render({ elem: '#txtFirstECGTime', type: 'datetime' });
    laydate.render({ elem: '#txtContact_Time', type: 'datetime' });
    laydate.render({ elem: '#txtTransTime', type: 'datetime' });
    laydate.render({ elem: '#txtXnkTime', type: 'datetime' });
    laydate.render({ elem: '#txtXnkTime2', type: 'datetime' });
    laydate.render({ elem: '#txtthrombolysisTime', type: 'datetime' });
    laydate.render({ elem: '#txtDrawBloodTime', type: 'datetime' });
    laydate.render({ elem: '#txtReportingTime', type: 'datetime' });
    laydate.render({ elem: '#txtOutTime', type: 'datetime' });
    laydate.render({ elem: '#txtlkbydmsj', type: 'datetime' });
    laydate.render({ elem: '#txtzdsj', type: 'datetime' });
    laydate.render({ elem: '#txtZksj', type: 'datetime' });
    laydate.render({ elem: '#txtJzsj', type: 'datetime' });
    laydate.render({ elem: '#txtDeadTime', type: 'datetime' });
    laydate.render({ elem: '#txtYqxdtTime', type: 'datetime' });
    laydate.render({ elem: '#txtDelivery_Time1', type: 'datetime' });
    laydate.render({ elem: '#txtCatheter_Ecg_Time', type: 'datetime' });
    laydate.render({ elem: '#txtTroponin_Blood_Time', type: 'datetime' });
    laydate.render({ elem: '#txtEcg_Time', type: 'datetime' });
    laydate.render({ elem: '#txtEcg_Confirmed_Time', type: 'datetime' });
    laydate.render({ elem: '#txtDoctorArriveTime', type: 'datetime' });
    laydate.render({ elem: '#txtArriveDoorTime', type: 'datetime' });
    laydate.render({ elem: '#txtSureTransferOutTime', type: 'datetime' });
    laydate.render({ elem: '#txtAmbulanceArriveTime', type: 'datetime' });
    laydate.render({ elem: '#txtConsultationTime', type: 'datetime' });
    laydate.render({ elem: "#txtLeaveTime", type: "datetime" });
    laydate.render({ elem: "#txtLeaveDepRoomTime", type: "datetime" });
    laydate.render({ elem: "#txtDoubt_Radiology_NoticeTime", type: "datetime" });
    laydate.render({ elem: "#txtDoubt_Radiology_ArriveTime", type: "datetime" });
    laydate.render({ elem: "#txtDoubt_Radiography_Time", type: "datetime" });
    laydate.render({ elem: "#txtDoubt_Radiography_DIAGNOSISTime", type: "datetime" });
    laydate.render({ elem: "#txtFirstDiagnosisTime", type: "datetime" });
    laydate.render({ elem: "#txtRoomMeetTime", type: "datetime" });
    laydate.render({ elem: "#txtECG_CONFIRM_TIME", type: "datetime" });
    laydate.render({ elem: "#txtDelivery_Time2", type: "datetime" });
    laydate.render({ elem: "#txtLeaveRoomTime", type: "datetime" });
    laydate.render({ elem: "#txtDeterminCatheterTime", type: "datetime" });
    laydate.render({ elem: "#txtStartinforConsentTime", type: "datetime" });
    laydate.render({ elem: "#txtSigninforConsentTime", type: "datetime" });
    laydate.render({ elem: "#txtRadiology_HeartSuper_Time", type: "datetime" });
    laydate.render({ elem: "#txtVisit_ECG_Time", type: "datetime" });
    laydate.render({ elem: "#txtVisit_Troponin_STime", type: "datetime" });
    laydate.render({ elem: "#txtVisit_Troponin_RTime", type: "datetime" });
    laydate.render({ elem: "#txtAntiplatelet_Time", type: "datetime" });
    laydate.render({ elem: "#txtPCI_Time", type: "datetime" });
    laydate.render({ elem: "#txtVisit_Diagnosis_Time", type: "datetime" });
});
$(function () {
    $("input[type=radio]").parent().addClass("radio_label");
    if (navigator.userAgent.indexOf("Firefox") > 0) { $(":radio,:checkbox").hide(); }
    $("input[type=radio][disabled!=disabled]").click(function () {
        $("input[type=radio][name='" + $(this).attr('name') + "']").parent().removeClass("checked")
        $(this).parent().addClass("checked");
    });
    $("input[type=radio][checked=checked]").parent().addClass("checked");
    $("input[type=checkbox]").parent().addClass("checkbox_label");
    $("input[type=checkbox][disabled!=disabled]").click(function (e) {
        if ($(this).parent().hasClass("checked"))
            $(this).parent().removeClass("checked");
        else
            $(this).parent().addClass("checked");
    });
    $("input[type=checkbox][checked=checked]").parent().addClass("checked");
});

var onSuccessProvince = false;
var onSuccessCity = false;
var onSuccessDistrict = false;

$(function () {
    //左侧菜单
    getNavList();
    position();

    //民族
    $("#ddlPatient_National").ligerComboBox({
        width: 118,
        isTextBoxMode: false,
        data: [
            { "ID": "01", "Name": "汉族" },
            { "ID": "02", "Name": "蒙古族" },
            { "ID": "03", "Name": "回族" },
            { "ID": "04", "Name": "藏族" },
            { "ID": "05", "Name": "维吾尔族" },
            { "ID": "06", "Name": "苗族" },
            { "ID": "07", "Name": "彝族" },
            { "ID": "08", "Name": "壮族" },
            { "ID": "09", "Name": "布依族" },
            { "ID": "10", "Name": "朝鲜族" },
            { "ID": "11", "Name": "满族" },
            { "ID": "12", "Name": "侗族" },
            { "ID": "13", "Name": "瑶族" },
            { "ID": "14", "Name": "白族" },
            { "ID": "15", "Name": "土家族" },
            { "ID": "16", "Name": "哈尼族" },
            { "ID": "17", "Name": "哈萨克族" },
            { "ID": "18", "Name": "傣族" },
            { "ID": "19", "Name": "黎族" },
            { "ID": "20", "Name": "傈僳族" },
            { "ID": "21", "Name": "佤族" },
            { "ID": "22", "Name": "拉祜族" },
            { "ID": "23", "Name": "高山族" },
            { "ID": "24", "Name": "畲族" },
            { "ID": "25", "Name": "水族" },
            { "ID": "26", "Name": "东乡族" },
            { "ID": "27", "Name": "纳西族" },
            { "ID": "28", "Name": "景颇族" },
            { "ID": "29", "Name": "柯尔克孜族" },
            { "ID": "30", "Name": "土族" },
            { "ID": "31", "Name": "达斡尔族" },
            { "ID": "32", "Name": "仫佬族" },
            { "ID": "33", "Name": "羌族" },
            { "ID": "34", "Name": "布朗族" },
            { "ID": "35", "Name": "撒拉族" },
            { "ID": "36", "Name": "毛难族" },
            { "ID": "37", "Name": "仡佬族" },
            { "ID": "38", "Name": "锡伯族" },
            { "ID": "39", "Name": "阿昌族" },
            { "ID": "40", "Name": "土族普米族" },
            { "ID": "41", "Name": "塔吉克族" },
            { "ID": "42", "Name": "怒族" },
            { "ID": "43", "Name": "乌孜别克族" },
            { "ID": "44", "Name": "俄罗斯族" },
            { "ID": "45", "Name": "鄂温克族" },
            { "ID": "46", "Name": "崩龙族" },
            { "ID": "47", "Name": "保安族" },
            { "ID": "48", "Name": "裕固族" },
            { "ID": "49", "Name": "京族" },
            { "ID": "50", "Name": "塔塔尔族" },
            { "ID": "51", "Name": "独龙族" },
            { "ID": "52", "Name": "鄂伦春族" },
            { "ID": "53", "Name": "赫哲族" },
            { "ID": "54", "Name": "门巴族" },
            { "ID": "55", "Name": "珞巴族" },
            { "ID": "56", "Name": "基诺族" },
            { "ID": "97", "Name": "其他" },
            { "ID": "98", "Name": "外国血统" }
        ],
        isMultiSelect: false,
        valueField: "ID",
        textField: "Name",
        valueFieldID: "Patient_NationalID",
        value: "01"
    });

    //加载主数据
    GetPatients(null);
    //心电远程传输
    $('input[name="LongRange"]').click(function () {
        LongRangeDivshowhide();
    });
    //绕行
    $('input[name="Bypass"]').click(function () {
        BypassDivshowhide();
    });
    //来院方式
    $("input[name=eventGrade]").click(function () {
        EventGradeDivshowhide();
    });
    //患者列表
    $("#selPatientList").change(function () {
        //GetCaseHistory($("#selPatientList").val());
        location.href = "/ChestPainCenter/MedicalRecords/Index?patientId=" + $("#selPatientList").val(); //初步诊断的显示问题所以得重新加载页面
    })
    $("#txtArriveKRoom").ligerComboBox({
        width: 135,
        data: [{ "ID": "1", "Name": "导管室" }, { "ID": "2", "Name": "CCU" }, { "ID": "3", "Name": "心内科病房" }, { "ID": "4", "Name": "其他" }],
        isMultiSelect: false,
        valueField: "Name",
        textField: "Name",
        value: '0',
        valueFieldID: 'txthdnArriveKRoom'
    });
    //$("#txtillAddress").ligerComboBox({
    //    width: 320,
    //    isTextBoxMode: true,
    //    data: [{ "ID": "家中", "Name": "家中" }, { "ID": "户外", "Name": "户外" }, { "ID": "院外", "Name": "院外" }, { "ID": "院内", "Name": "院内" }],
    //    isMultiSelect: false,
    //    valueField: "ID",
    //    textField: "Name",
    //    value: ""
    //});

    $("#ddlProvince").ligerComboBox({
        url: "/ChestPainCenter/MedicalRecords/GetProvince",
        width: 100,
        cancelable: false,
        valueField: "Province",
        textField: "Province",
        valueFieldID: "hdnProvince",
        onSelected: function (value) {
            $("#ddlCity").ligerComboBox({
                url: "/ChestPainCenter/MedicalRecords/GetCity",
                parms: { province: value }
            });
        },
        onSuccess: function () {
            onSuccessProvince = true;
        }
    });

    $("#ddlCity").ligerComboBox({
        width: 100,
        cancelable: false,
        valueField: "City",
        textField: "City",
        valueFieldID: "hdnCity",
        onSelected: function (value) {
            $("#ddlDistrict").ligerComboBox({
                url: "/ChestPainCenter/MedicalRecords/GetDistrict",
                parms: { city: value }
            });
        },
        onSuccess: function () {
            onSuccessCity = true;
        }
    });

    $("#ddlDistrict").ligerComboBox({
        width: 100,
        cancelable: false,
        valueField: "District",
        textField: "District",
        valueFieldID: "hdnDistrict",
        onSuccess: function () {
            onSuccessDistrict = true;
        }
    });

    //是否死亡
    $("input[name=die_Bool]").click(function () {
        showDieInfo();
    });

    //是否呼叫心内科会诊
    $("input[name=IS_NOTICE_IMCD_Ex]").click(function () {
        $("[class^=divIS_NOTICE_IMCD_Ex]").hide();
        $("#txtMeetRoomName").hide();
        if ($(this).val() == 0) {
            $("#txtRoomMeetTime").val("");
            $("#txtMedical_DoctorName").val("");
            $("#txtMeetRoomName").ligerComboBox().setValue("");
        }
        $(".divIS_NOTICE_IMCD_Ex" + $(this).val()).show();
    });

    //STEMI》溶栓》院内溶栓筛查
    $("input[name=rdoDiagnosticPath1_ZaiGuanZhuCuoShi1_RongShuanShaiCha]").click(function () {
        $("[class^=DiagnosticPath1_ZaiGuanZhuCuoShi1_RongShuanShaiCha]").hide();
        $(".DiagnosticPath1_ZaiGuanZhuCuoShi1_RongShuanShaiCha" + $(this).val()).show();
    });

    $(".t8").find("label:not(.radio_label,.checkbox_label)").css("margin-right", "0px");

    setDiagnosticPathDisplay();
    setDiagnosticPathLayDate();

    upload("btnAddPic1", "<div style=\"font-size:30px;font-weight:bold;\">+</div><div style=\"font-size:12px;\">院前心电图</div>", 1);
    upload("btnAddPic3", "<div style=\"font-size:30px;font-weight:bold;\">+</div><div style=\"font-size:12px;\">院内心电图</div>", 3);
    upload("btnAddPic4", "<div style=\"font-size:30px;font-weight:bold;\">+</div><div style=\"font-size:12px;\">心超图</div>", 4);
});
//--*******************图片 上传/预览/大图*****---//
var imageUploadPath = "/upload/images/";
$(function () {
    $(".btn-close").on("click", function () {
        var id = $(this).attr("id").toString().replace("btnClose", "");
        $("#txtImage" + id + "_ADD").val("");
        $("#txtfile" + id + "pass").val("0");
        $("#imageview" + id).hide();
        $(this).hide();
        $("#imageview" + id).css("display", "none");
        $(this).css("display", "none");
    })
});
function checkHasImg(id) {
    if ($("#imageview" + id).length == 1) {
        var ImgObj = new Image();
        ImgObj.src = $("#imageview" + id).attr("src");
        if (checkImageName(ImgObj.src) && (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0))) {
            $("#imageview" + id).show();
            $("#btnClose" + id).show();
        } else {
            $("#imageview" + id).hide();
            $("#btnClose" + id).hide();
        }
    }
}
//--*******************图片 上传/预览/大图*****---//
function position() {
    LiftEffect({
        "control1": ".lift-nav",
        "control2": ".lift",
        "target": [".t0", ".t1", ".t2", ".t4", ".t5", ".t6", ".t7", ".t8", ".t10", ".t12", ".t11", ".t9"],
        "current": "current"
    });
}
var Lname = '', Lsex = '', Lage = '', Ldis = '';
var waitting2;
function GetCaseHistory(patientId) {
    if (IsEmpty(patientId)) return;
    waitting2 = $.ligerDialog.waitting('加载中，请稍后...');
    $.ajax({
        url: "/ChestPainCenter/MedicalRecords/GetCaseHistory?Pid=" + patientId,
        cache: false,
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                var jsonData = $.parseJSON(d.Body);
                //*******************************初步诊断动态控件开始*******************************
                var pathid = jsonData.DiagnosticPathId;
                $("#DiagnosticPathId").val(pathid);
                //GetPathNameList(pathid);
                //GetDiagnosticPathTemp(pathid, $("#selPatientList").val());
                setDiagnosticPath($("#selPatientList").val());
                //*******************************初步诊断动态控件结束*******************************
                //*******************************基本信息开始*******************************
                if (jsonData.PreDiagnosis == null) {
                    $("#Disease").text("未诊断");
                } else {
                    $("#Disease").text(jsonData.PreDiagnosis);
                    Ldis = jsonData.PreDiagnosis;
                }
                ControlSetVal("txtName", jsonData.PatientName);
                Lname = jsonData.PatientName;
                ControlSetVal("selSex", jsonData.PatientSex);
                Lsex = jsonData.PatientSex;
                ControlSetVal("txtAge", jsonData.PatientAge);
                Lage = jsonData.PatientAge;
                ControlSetVal("txtPhone", jsonData.PatientPhone);
                ControlSetVal("txtID", jsonData.PatientId);
                ControlSetVal("txtHospital_ID", jsonData.Hospital_ID);
                ControlSetVal("pidd", jsonData.PatientId);
                ControlSetVal("txtCardID", jsonData.PatientIdNum);
                ControlSetVal("txtAddress", jsonData.PatientAddr);
                //*******************************基本信息结束*******************************
                //*******************************发病时间开始*******************************
                ControlSetVal("dtDiseaseTime", obj2Timemm(jsonData.EmsDiseaseTime));
                ControlSetVal("txtHelpTime", obj2Timemm(jsonData.HelpTime));
                $("#ddlPatient_National").ligerComboBox().setValue(jsonData.Patient_National);
                //发病地址 
                ControlSetVal("txtillAddress", jsonData.EMS_DISEASE_ADDR);
                //*******************************发病时间结束*******************************
                //*******************************病情评估开始*******************************
                //病情评估$('input:radio[name="illestimateList"]')
                RadioSetVal("illestimateList", jsonData.ConditionAssessment, true);
                //*******************************病情评估结束*******************************
                //*******************************来院方式开始*******************************
                //来院方式
                RadioSetVal("eventGrade", jsonData.PatientArriveClass, true);
                EventGradeDivshowhide();
                //出车单位
                RadioSetVal("CarType", jsonData.CarType, true);
                //医生出诊到达现场时间 $("#txtDoctorArriveTime")
                ControlSetVal("txtDoctorArriveTime", obj2Timemm(jsonData.DoctorArriveTime));
                //医院名称 $("#txtTransferOutHospital")
                ControlSetVal("txtTransferOutHospital", jsonData.TransferOutHospital);
                //转出医院入门时间 $("#txtArriveDoorTime")
                ControlSetVal("txtArriveDoorTime", obj2Timemm(jsonData.ArriveDoorTime));
                //决定转院时间 $("#txtSureTransferOutTime")
                ControlSetVal("txtSureTransferOutTime", obj2Timemm(jsonData.SureTransferOutTime));
                //转运救护车到达时间 $("#txtAmbulanceArriveTime")
                ControlSetVal("txtAmbulanceArriveTime", obj2Timemm(jsonData.AmbulanceArriveTime));
                //离开转出医院 $("#txtLeaveTime")
                ControlSetVal("txtLeaveTime", obj2Timemm(jsonData.LeaveTime));
                //发病科室 $("#txtDiseaseDep")
                $("#txtDiseaseDep").ligerComboBox().setText(jsonData.DiseaseDep);
                $("#txtDiseaseDep").ligerComboBox().setValue(jsonData.DiseaseDep);
                //会诊时间 $("#txtConsultationTime")
                ControlSetVal("txtConsultationTime", obj2Timemm(jsonData.ConsultationTime));
                //离开科室时间 $("#txtLeaveDepRoom")
                ControlSetVal("txtLeaveDepRoomTime", obj2Timemm(jsonData.LeaveDepTime));
                //医院名称 $("#txtzwyy2")
                ControlSetVal("txtArriveTime", obj2Timemm(jsonData.EmsArriveDoorTime));
                ControlSetVal("txtReceiveTime", obj2Timemm(jsonData.HMedicalTime));
                //是否绕行
                RadioSetVal("Bypass", jsonData.IsRound, true);
                //是否绕行事件
                BypassDivshowhide();
                //直达科室参考赋值
                $("#txtArriveKRoom").ligerGetComboBoxManager().setValue(jsonData.ThroughToDep);
                //到达时间
                ControlSetVal("txtArriveBypass", obj2Timemm(jsonData.ThroughToTime));
                //*******************************来院方式结束*******************************
                //*******************************首次医疗接触开始*******************************
                RadioSetVal("FirstT", jsonData.AMFirst_Institutions, true);
                ControlSetVal("txtNurse", jsonData.AMMedical_Name);
                ControlSetVal("txtFirstECGTime", obj2Timemm(jsonData.AMBULANCE_Contact_Time));
                //院前心电图时间
                //$("#txtYqxdtTime")
                ControlSetVal("txtYqxdtTime", obj2Timemm(jsonData.AMEcg_Time));
                //院前心电图图片url赋值参考
                //console.log("1" + jsonData.Image1_ADD);
                var imageUrls1 = jsonData.Image1_ADD;
                //if (IsEmpty(imageUrls1)) imageUrls1 = "#######"
                //if (imageUrls1.toString().indexOf("#") < 0) {
                //    if (checkImageName(imageUrls1)) {
                //        $("#txtfile11pass").val(1);
                //        $("#txtImage11_ADD").val(imageUrls1);
                //        var imgUrl1 = thisHostWithHttp() + imageUploadPath + imageUrls1;
                //        $("#imageview11").attr("src", imgUrl1);
                //        $("#btnClose11").show();
                //    } else {
                //        $("#imageview11").attr("src", "");
                //        $("#txtfile11pass").val(0);
                //        $("#txtImage11_ADD").val("");
                //        $("#imageview11").hide();
                //        $("#btnClose11").hide();
                //    }
                //} else {
                //    var index = 0;
                //    var imageUrlArr = imageUrls1.toString().split("#");
                //    for (var id = 11; id <= 18; id++) {
                //        if (checkImageName(imageUrlArr[index])) {
                //            $("#txtfile" + id + "pass").val(1);
                //            $("#txtImage" + id + "_ADD").val(imageUrlArr[index].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //            var imgUrl = imageUrlArr[index];
                //            $("#imageview" + id).attr("src", imgUrl);
                //            $("#btnClose" + id).show();
                //        } else {
                //            $("#imageview" + id).attr("src", "");
                //            $("#txtfile" + id + "pass").val(0);
                //            $("#txtImage" + id + "_ADD").val("");
                //            $("#imageview" + id).hide();
                //            $("#btnClose" + id).hide();
                //        }
                //        index++;
                //    }
                //}
                //var imageUrlArr = imageUrls1.toString().split("#");
                //var id = 11;
                //for (var i = 0; i < imageUrlArr.length; i++) {
                //    if (checkImageName(imageUrlArr[i])) {
                //        $("#txtfile" + id + "pass").val(1);
                //        $("#txtImage" + id + "_ADD").val(imageUrlArr[i].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //        var imgUrl = imageUrlArr[i];
                //        if (imgUrl.indexOf(imageUploadPath) == -1) {
                //            imgUrl = thisHostWithHttp() + imageUploadPath + imageUrls1;
                //        }
                //        $("#imageview" + id).attr("src", imgUrl);
                //        $("#btnClose" + id).show();
                //    } else {
                //        $("#imageview" + id).attr("src", "");
                //        $("#txtfile" + id + "pass").val(0);
                //        $("#txtImage" + id + "_ADD").val("");
                //        $("#imageview" + id).hide();
                //        $("#btnClose" + id).hide();
                //    }
                //    id++;
                //}
                if (!IsEmpty(imageUrls1)) {
                    $(".photo1").remove();
                    var imgList = imageUrls1.split('#');
                    for (var i = 0; i < imgList.length; i++) {
                        var photo = $("<div class=\"photo1\" style=\"float:left;margin-left:10px;margin-top:10px;text-align:center;\"><img class=\"imgUpload1\" src=\"" + imgList[i] + "\" style=\"height:60px;width:60px;\"  onclick=\"window.open('" + imgList[i] + "');\"/><p style=\"color:#808080;cursor:default;\" onclick=\"delFile(this,'" + imageUploadPath + imgList[i].split('/')[imgList[i].split('/').length - 1] + "',1)\">删除</p></div>");
                        $("#tdPhoto1").append(photo);
                    }
                    $(".photo1").eq(0).css('margin-left', 0);
                    if ($(".photo1").length >= 8) {
                        $("#btnAddPic1").hide();
                    }
                }

                //给药时间
                //$("#txtDelivery_Time1")
                ControlSetVal("txtDelivery_Time1", obj2Timemm(jsonData.Delivery_Time));
                //是否阿司匹林
                //$("#cbxisAspirin")
                CheckedFromVal("cbxisAspirin", jsonData.Aspirin);
                //是否替格瑞洛 
                //$("#cbxisTicagrelor")
                CheckedFromVal("cbxisTicagrelor", jsonData.Ticagrelor);
                //是否氯吡格雷
                //$("#cbxisClopidogrel")
                CheckedFromVal("cbxisClopidogrel", jsonData.Clopidogrel);
                //阿司匹林mg
                //$("#txtmgAspirin")
                ControlSetVal("txtmgAspirin", jsonData.Aspirin);
                //替格瑞洛mg
                //$("#txtmgTicagrelor")
                ControlSetVal("txtmgTicagrelor", jsonData.Ticagrelor);
                //氯吡格雷mg
                //$("#txtmgClopidogrel")
                ControlSetVal("txtmgClopidogrel", jsonData.Clopidogrel);

                //新药1
                ControlSetVal("txtmgRosuvastatin", jsonData.Rosuvastatin);
                CheckedFromVal("cbxisRosuvastatin", jsonData.Rosuvastatin);
                ControlSetVal("txtmgAtorvastatin", jsonData.Atorvastatin);
                CheckedFromVal("cbxisAtorvastatin", jsonData.Atorvastatin);
                ControlSetVal("txtmgHeparin", jsonData.Heparin);
                CheckedFromVal("cbxisHeparin", jsonData.Heparin);


                //导管室心电图时间
                //$("#txtCatheter_Ecg_Time")
                ControlSetVal("txtCatheter_Ecg_Time", obj2Timemm(jsonData.Catheter_Ecg_Time));
                //肌钙蛋白抽血时间
                //$("#txtTroponin_Blood_Time")
                ControlSetVal("txtTroponin_Blood_Time", obj2Timemm(jsonData.Troponin_Blood_Time));
                //导管室心电图图片url赋值参考.
                //console.log("2" + jsonData.Image2_ADD);
                var imageUrls2 = jsonData.Image2_ADD;
                if (IsEmpty(imageUrls2)) imageUrls2 = "#######";
                //if (imageUrls2.toString().indexOf("#") < 0) {
                //    if (checkImageName(imageUrls2)) {
                //        $("#txtfile21pass").val(1);
                //        $("#txtImage21_ADD").val(imageUrls2);
                //        var imgUrl2 = thisHostWithHttp() + imageUploadPath + imageUrls2;
                //        $("#imageview21").attr("src", imgUrl2);
                //        $("#btnClose21").show();
                //    } else {
                //        $("#imageview21").attr("src", "");
                //        $("#txtfile21pass").val(0);
                //        $("#txtImage21_ADD").val("");
                //        $("#imageview21").hide();
                //        $("#btnClose21").show();
                //    }
                //} else {
                //    var index = 0;
                //    var imageUrlArr = imageUrls2.toString().split("#");
                //    for (var id = 21; id <= 28; id++) {
                //        if (checkImageName(imageUrlArr[index])) {
                //            $("#txtfile" + id + "pass").val(1);
                //            $("#txtImage" + id + "_ADD").val(imageUrlArr[index].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //            var imgUrl = imageUrlArr[index];
                //            $("#imageview" + id).attr("src", imgUrl);
                //            $("#btnClose" + id).show();
                //        } else {
                //            $("#imageview" + id).attr("src", "");
                //            $("#txtfile" + id + "pass").val(0);
                //            $("#txtImage" + id + "_ADD").val("");
                //            $("#imageview" + id).hide();
                //            $("#btnClose" + id).hide();
                //        }
                //        index++;
                //    }
                //}
                imageUrlArr = imageUrls2.toString().split("#");
                var id = 21;
                for (var i = 0; i < imageUrlArr.length; i++) {
                    if (checkImageName(imageUrlArr[i])) {
                        $("#txtfile" + id + "pass").val(1);
                        $("#txtImage" + id + "_ADD").val(imageUrlArr[i].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                        var imgUrl = imageUrlArr[i];
                        if (imgUrl.indexOf(imageUploadPath) == -1) {
                            imgUrl = thisHostWithHttp() + imageUploadPath + imageUrls1;
                        }
                        $("#imageview" + id).attr("src", imgUrl);
                        $("#btnClose" + id).show();
                    } else {
                        $("#imageview" + id).attr("src", "");
                        $("#txtfile" + id + "pass").val(0);
                        $("#txtImage" + id + "_ADD").val("");
                        $("#imageview" + id).hide();
                        $("#btnClose" + id).hide();
                    }
                    id++;
                }

                //院内首次机构
                RadioSetVal("FirstT2", jsonData.First_Institutions, true);

                ControlSetVal("txtFirstDiagnosisTime", obj2Timemm(jsonData.FirstDiagnosisTime));
                ControlSetVal("txtRoomMeetTime", obj2Timemm(jsonData.RoomMeetTime));
                $("#txtMeetRoomName").ligerComboBox().setText(jsonData.MeetRoomName);
                $("#txtMeetRoomName").ligerComboBox().setValue(jsonData.MeetRoomName);
                ControlSetVal("txtDelivery_Time2", obj2Timemm(jsonData.DeliveryTime));
                ControlSetVal("txtmgAspirin2", jsonData.AspirinYn);
                ControlSetVal("txtmgTicagrelor2", jsonData.TicagrelorYn);
                ControlSetVal("txtmgClopidogrel2", jsonData.ClopidogrelYn);
                ControlSetVal("txtLeaveRoomTime", obj2Timemm(jsonData.LeaveRoomTime));
                CheckedFromVal("cbxisAspirin2", jsonData.AspirinYn);
                CheckedFromVal("cbxisTicagrelor2", jsonData.TicagrelorYn);
                CheckedFromVal("cbxisClopidogrel2", jsonData.ClopidogrelYn);

                //新药2
                ControlSetVal("txtmgRosuvastatin2", jsonData.RosuvastatinYn);
                CheckedFromVal("cbxisRosuvastatin2", jsonData.RosuvastatinYn);
                ControlSetVal("txtmgAtorvastatin2", jsonData.AtorvastatinYn);
                CheckedFromVal("cbxisAtorvastatin2", jsonData.AtorvastatinYn);

                ControlSetVal("txtDeterminCatheterTime", obj2Timemm(jsonData.DeterminCatheterTime));
                ControlSetVal("txtStartinforConsentTime", obj2Timemm(jsonData.StartinforConsentTime));
                ControlSetVal("txtSigninforConsentTime", obj2Timemm(jsonData.SigninforConsentTime));
                ControlSetVal("txtEnzyme", jsonData.Enzyme);
                ControlSetVal("txtUrokinase", jsonData.Urokinase);
                CheckedFromVal("cbxisEnzyme", jsonData.Enzyme);
                CheckedFromVal("cbxisUrokinase", jsonData.Urokinase);
                ControlSetVal("txtGuessD2BMins", jsonData.GuessD2BMins);


                //医护人员 院内
                //$("#txtNurse2")
                ControlSetVal("txtMedical_Name", jsonData.Medical_Name);
                //接触时间 院内
                //$("#txtContact_Time")
                ControlSetVal("txtContact_Time", obj2Timemm(jsonData.Contact_Time));
                //心电图时间 院内 第一次
                //$("txtEcg_Time")
                ControlSetVal("txtEcg_Time", obj2Timemm(jsonData.Ecg_Time));
                //心电图诊断时间 院内 第二次
                ControlSetVal("txtECG_CONFIRM_TIME", obj2Timemm(jsonData.EcgConfirmTime));
                //心电图确诊时间 院内 第三次
                //$("#txtEcg_Confirmed_Time")
                //ControlSetVal("txtEcg_Confirmed_Time", obj2Timemm(jsonData.Ecg_Confirmed_Time));
                //院内心电图图片url赋值参考
                //console.log("3" + jsonData.Image_ADD);
                var imageUrls3 = jsonData.Image_ADD;
                //if (IsEmpty(imageUrls3)) imageUrls3 = "#######";
                //if (imageUrls3.toString().indexOf("#") < 0) {
                //    if (checkImageName(imageUrls3)) {
                //        $("#txtfile31pass").val(1);
                //        $("#txtImage31_ADD").val(imageUrls3);
                //        var imgUrl = thisHostWithHttp() + imageUploadPath + imageUrls3;
                //        $("#imageview31").attr("src", imgUrl);
                //        $("#btnClose31").show();
                //    } else {
                //        $("#imageview31").attr("src", "");
                //        $("#txtfile31pass").val(0);
                //        $("#txtImage31_ADD").val("");
                //        $("#imageview31").hide();
                //        $("#btnClose31").hide();
                //    }
                //} else {
                //    var index = 0;
                //    var imageUrlArr = imageUrls3.toString().split("#");
                //    for (var id = 31; id <= 38; id++) {
                //        if (checkImageName(imageUrlArr[index])) {
                //            $("#txtfile" + id + "pass").val(1);
                //            $("#txtImage" + id + "_ADD").val(imageUrlArr[index].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //            var imgUrl = imageUrlArr[index];
                //            $("#imageview" + id).attr("src", imgUrl);
                //            $("#btnClose" + id).show();
                //        } else {
                //            $("#imageview" + id).attr("src", "");
                //            $("#txtfile" + id + "pass").val(0);
                //            $("#txtImage" + id + "_ADD").val("");
                //            $("#imageview" + id).hide();
                //            $("#btnClose" + id).hide();
                //        }
                //        index++;
                //    }
                //}
                //imageUrlArr = imageUrls3.toString().split("#");
                //var id = 31;
                //for (var i = 0; i < imageUrlArr.length; i++) {
                //    if (checkImageName(imageUrlArr[i])) {
                //        $("#txtfile" + id + "pass").val(1);
                //        $("#txtImage" + id + "_ADD").val(imageUrlArr[i].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //        var imgUrl = imageUrlArr[i];
                //        if (imgUrl.indexOf(imageUploadPath) == -1) {
                //            imgUrl = thisHostWithHttp() + imageUploadPath + imageUrls1;
                //        }
                //        $("#imageview" + id).attr("src", imgUrl);
                //        $("#btnClose" + id).show();
                //    } else {
                //        $("#imageview" + id).attr("src", "");
                //        $("#txtfile" + id + "pass").val(0);
                //        $("#txtImage" + id + "_ADD").val("");
                //        $("#imageview" + id).hide();
                //        $("#btnClose" + id).hide();
                //    }
                //    id++;
                //}
                if (!IsEmpty(imageUrls3)) {
                    $(".photo3").remove();
                    var imgList = imageUrls3.split('#');
                    for (var i = 0; i < imgList.length; i++) {
                        var photo = $("<div class=\"photo3\" style=\"float:left;margin-left:10px;margin-top:10px;text-align:center;\"><img class=\"imgUpload3\" src=\"" + imgList[i] + "\" style=\"height:60px;width:60px;\"  onclick=\"window.open('" + imgList[i] + "');\"/><p style=\"color:#808080;cursor:default;\" onclick=\"delFile(this,'" + imageUploadPath + imgList[i].split('/')[imgList[i].split('/').length - 1] + "',3)\">删除</p></div>");
                        $("#tdPhoto3").append(photo);
                    }
                    $(".photo3").eq(0).css('margin-left', 0);
                    if ($(".photo3").length >= 8) {
                        $("#btnAddPic3").hide();
                    }
                }

                //心超图图片url赋值参考
                //console.log("4" + jsonData.Radiology_HeartSuper_ADD);
                var imageUrls4 = jsonData.Radiology_HeartSuper_ADD;
                //if (IsEmpty(imageUrls4)) imageUrls4 = "#######"
                //if (imageUrls1.toString().indexOf("#") < 0) {
                //    if (checkImageName(imageUrls1)) {
                //        $("#txtfile41pass").val(1);
                //        $("#txtImage41_ADD").val(imageUrls1);
                //        var imgUrl1 = thisHostWithHttp() + imageUploadPath + imageUrls1;
                //        $("#imageview41").attr("src", imgUrl1);
                //        $("#btnClose41").show();
                //    } else {
                //        $("#imageview41").attr("src", "");
                //        $("#txtfile41pass").val(0);
                //        $("#txtImage41_ADD").val("");
                //        $("#imageview41").hide();
                //        $("#btnClose41").hide();
                //    }
                //} else {
                //    var index = 0;
                //    var imageUrlArr = imageUrls1.toString().split("#");
                //    for (var id = 41; id <= 48; id++) {
                //        if (checkImageName(imageUrlArr[index])) {
                //            $("#txtfile" + id + "pass").val(1);
                //            $("#txtImage" + id + "_ADD").val(imageUrlArr[index].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //            var imgUrl = imageUrlArr[index];
                //            $("#imageview" + id).attr("src", imgUrl);
                //            $("#btnClose" + id).show();
                //        } else {
                //            $("#imageview" + id).attr("src", "");
                //            $("#txtfile" + id + "pass").val(0);
                //            $("#txtImage" + id + "_ADD").val("");
                //            $("#imageview" + id).hide();
                //            $("#btnClose" + id).hide();
                //        }
                //        index++;
                //    }
                //}
                //imageUrlArr = imageUrls4.toString().split("#");
                //var id = 41;
                //for (var i = 0; i < imageUrlArr.length; i++) {
                //    if (checkImageName(imageUrlArr[i])) {
                //        $("#txtfile" + id + "pass").val(1);
                //        $("#txtImage" + id + "_ADD").val(imageUrlArr[i].toString().replace(thisHostWithHttp() + imageUploadPath, ""));
                //        var imgUrl = imageUrlArr[i];
                //        if (imgUrl.indexOf(imageUploadPath) == -1) {
                //            imgUrl = thisHostWithHttp() + imageUploadPath + imageUrls1;
                //        }
                //        $("#imageview" + id).attr("src", imgUrl);
                //        $("#btnClose" + id).show();
                //    } else {
                //        $("#imageview" + id).attr("src", "");
                //        $("#txtfile" + id + "pass").val(0);
                //        $("#txtImage" + id + "_ADD").val("");
                //        $("#imageview" + id).hide();
                //        $("#btnClose" + id).hide();
                //    }
                //    id++;
                //}
                if (!IsEmpty(imageUrls4)) {
                    $(".photo4").remove();
                    var imgList = imageUrls4.split('#');
                    for (var i = 0; i < imgList.length; i++) {
                        var photo = $("<div class=\"photo4\" style=\"float:left;margin-left:10px;margin-top:10px;text-align:center;\"><img class=\"imgUpload4\" src=\"" + imgList[i] + "\" style=\"height:60px;width:60px;\"  onclick=\"window.open('" + imgList[i] + "');\"/><p style=\"color:#808080;cursor:default;\" onclick=\"delFile(this,'" + imageUploadPath + imgList[i].split('/')[imgList[i].split('/').length - 1] + "',4)\">删除</p></div>");
                        $("#tdPhoto4").append(photo);
                    }
                    $(".photo4").eq(0).css('margin-left', 0);
                    if ($(".photo4").length >= 8) {
                        $("#btnAddPic4").hide();
                    }
                }

                ControlSetVal("txtRadiology_HeartSuper_Time", obj2Timemm(jsonData.Radiology_HeartSuper_Time));
                ControlSetVal("txtDoubt_Radiology_NoticeTime", obj2Timemm(jsonData.Doubt_Radiology_NoticeTime));
                ControlSetVal("txtDoubt_Radiology_ArriveTime", obj2Timemm(jsonData.Doubt_Radiology_ArriveTime));
                ControlSetVal("txtDoubt_Radiography_Time", obj2Timemm(jsonData.Doubt_Radiography_Time));
                ControlSetVal("txtDoubt_Radiography_DIAGNOSISTime", obj2Timemm(jsonData.Doubt_Radiography_DIAGNOSISTime));
                RadioSetVal("Doubt_Radiography_DIAGNOSIS", jsonData.Doubt_Radiography_DIAGNOSIS, true);
                //*******************************首次医疗接触结束*******************************
                //*******************************远程心电开始*******************************               
                RadioSetVal("LongRange", jsonData.IsEcgTransmission, true);
                LongRangeDivshowhide();
                ControlSetVal("selTransType", jsonData.TransmissionClass);
                ControlSetVal("txtTransTime", obj2Timemm(jsonData.TransmissionTime));
                //*******************************远程心电结束*******************************
                //*******************************会诊情况开始*******************************
                ControlSetVal("txtXnkDoc", jsonData.CardiologistName);
                ControlSetVal("txtXnkTime", obj2Timemm(jsonData.ConsultatTime));
                ControlSetVal("txtXnkTime2", obj2Timemm(jsonData.StartCatheterTime));

                //溶栓地点
                RadioSetVal("thrombolysisAddr", jsonData.ThrombolysisAddr, true);
                ControlSetVal("txtthrombolysisTime", obj2Timemm(jsonData.ThrombolysisTime));
                ControlSetVal("txtthrombolysisMedi", jsonData.ThrombolysisMedicine);
                ControlSetVal("txtthrombolysisMetering", jsonData.ThrombolysisDose);
                ControlSetVal("txtMedical_DoctorName", jsonData.Medical_DoctorName);
                //*******************************会诊情况结束*******************************
                //*******************************生命体征开始*******************************                
                RadioSetVal("Conscious", jsonData.PatientConsciousness, true);
                ControlSetVal("txtBreath", jsonData.PatientBreathe);
                ControlSetVal("txtPulse", jsonData.PatientPulse);
                ControlSetVal("txtHeartRate", jsonData.PatientHeart);
                ControlSetVal("txtBloodPressure", jsonData.PatientBloodH);
                ControlSetVal("txtBloodPressure2", jsonData.PatientBloodL);
                ControlSetVal("txtPATIENT_SPO2", jsonData.PATIENT_SPO2);
                //*******************************生命体征结束*******************************
                //*******************************辅助检查开始*******************************
                ControlSetVal("txtDrawBloodTime", obj2Timemm(jsonData.DrawBloodTime));
                ControlSetVal("txtReportingTime", obj2Timemm(jsonData.ReportTime));
                ControlSetVal("txtcTnl", jsonData.CtnlValue);
                ControlSetVal("selcTnlUnit", jsonData.CtnlUnit);
                ControlSetVal("selcTnlType", jsonData.CtnlStatus);
                ControlSetVal("txtcTnT", jsonData.CtntValue);
                ControlSetVal("selcTnTUnit", jsonData.CtntUnit);
                ControlSetVal("selcTnTType", jsonData.CtntStatus);
                ControlSetVal("txtxqjg", jsonData.CrValue);
                ControlSetVal("selxqjgUnit", jsonData.CrUnit);
                ControlSetVal("txtAuxiliary_Tnl_Float", jsonData.Auxiliary_Tnl_Float);
                ControlSetVal("txtAuxiliary_CKMB_Float", jsonData.Auxiliary_CKMB_Float);
                ControlSetVal("txtAuxiliary_Myo_Float", jsonData.Auxiliary_Myo_Float);
                ControlSetVal("txtAuxiliary_Age_Float", jsonData.Auxiliary_Age_Float);
                //*******************************辅助检查结束*******************************
                //*******************************转归情况开始*******************************
                ControlSetVal("txtLeaveHospitalTime", obj2Timemm(jsonData.LeaveHospitalTime));
                RadioSetVal("OutComeType", jsonData.OutComeType, true);
                CheckBoxSetVal("TakeMedicineType", jsonData.TakeMedicineType, true);
                ControlSetVal("txtlkbydmsj", obj2Timemm(jsonData.LeaveDoorTime));
                ControlSetVal("txtzwyy", jsonData.TransferHospitalName);
                ControlSetVal("txtzdsj", obj2Timemm(jsonData.TransferArriveTime));
                ControlSetVal("txtReason", jsonData.TransferReason);
                RadioSetVal("YzPCI", jsonData.IsPCI, true);
                RadioSetVal("Zddgs", jsonData.IsDirectCatheter, true);
                ControlSetVal("txtZksj", obj2Timemm(jsonData.TransferDepTime));
                ControlSetVal("txtJzsj", obj2Timemm(jsonData.ReceptionTime));
                ControlSetVal("txtZkyyms", jsonData.TransferDepReason);
                ControlSetVal("txtDeadTime", obj2Timemm(jsonData.DieTime));
                RadioSetVal("Sfxyx", jsonData.IsCardiogenic, true);
                ControlSetVal("txtDeadDescription", jsonData.DieDescribe);
                RadioSetVal("die_Bool", jsonData.Die_Bool, true);
                showDieInfo();
                //*******************************转归情况结束*******************************

                //*******************************实施措施***********************************

                RadioSetVal("rdoKillip_LV", jsonData.Killip_LV, true);
                RadioSetVal("rdoNYHA_LV", jsonData.NYHA_LV, true);
                CheckBoxSetVal("chkNYHA_Type", jsonData.NYHA_Type, true);
                CheckBoxSetVal("chkSTEMI_Methods", jsonData.STEMI_Methods, true);
                CheckBoxSetVal("chkNSTE_ACS", jsonData.NSTE_ACS, true);
                ControlSetVal("txtPCI_Time", obj2Timemm(jsonData.PCI_Time));
                ControlSetVal("txtAntiplatelet_Time", obj2Timemm(jsonData.Antiplatelet_Time));
                ControlSetVal("txtAntiplatelet_Aspirin", jsonData.Antiplatelet_Aspirin);
                CheckedFromVal("chkisAntiplatelet_Aspirin", jsonData.Antiplatelet_Aspirin);
                ControlSetVal("txtAntiplatelet_Ticagrelor", jsonData.Antiplatelet_Ticagrelor);
                CheckedFromVal("chkisAntiplatelet_Ticagrelor", jsonData.Antiplatelet_Ticagrelor);
                ControlSetVal("txtAntiplatelet_Clopidogrel", jsonData.Antiplatelet_Clopidogrel);
                CheckedFromVal("chkisAntiplatelet_Clopidogrel", jsonData.Antiplatelet_Clopidogrel);
                RadioSetVal("rdoTreatment_24H_Bool", jsonData.Treatment_24H_Bool, true);
                RadioSetVal("rdoTreatment_Blockers_Bool", jsonData.Treatment_Blockers_Bool, true);

                //*******************************实施措施结束*******************************

                //*******************************复测***************************************

                ControlSetVal("txtVisit_ECG_Time", obj2Timemm(jsonData.Visit_ECG_Time));
                ControlSetVal("txtVisit_Troponin_STime", obj2Timemm(jsonData.Visit_Troponin_STime));
                ControlSetVal("txtVisit_Troponin_RTime", obj2Timemm(jsonData.Visit_Troponin_RTime));
                ControlSetVal("txtVisit_Troponin_Result", jsonData.Visit_Troponin_Result);
                CheckBoxSetVal("chkGrace_Risk_LV", jsonData.Grace_Risk_LV, true);
                CheckBoxSetVal("chkGrace_Risk_Type", jsonData.Grace_Risk_Type, true);
                RadioSetVal("rdoVisit_Diagnosis", jsonData.Visit_Diagnosis, true);
                ControlSetVal("txtVisit_Diagnosis_Time", obj2Timemm(jsonData.Visit_Diagnosis_Time));

                //*******************************复测结束***********************************

                var exList = [];
                $("[name$=_Ex]").each(function () {
                    var name = $(this).attr("name");
                    if (jQuery.inArray(name, exList) == -1) {
                        exList.push(name);
                    }
                });
                for (var i = 0; i < exList.length; i++) {
                    var field = exList[i].replace("_Ex", "");
                    var item = $("[name='" + exList[i] + "']");
                    if (item[0].tagName.toLowerCase() == "input") {
                        var type = item.attr("type").toLowerCase();
                        if (type == "text") {
                            if (!item.hasClass("Ldate-datetime")) {
                                if (field == "PATIENT_ADDR_Province" && !IsEmpty(eval("jsonData." + field))) {
                                    $("#hdnProvince").val(eval("jsonData." + field));
                                    var t1 = window.setInterval(function () {
                                        if (onSuccessProvince == true) {
                                            $("#ddlProvince").ligerComboBox().setValue($("#hdnProvince").val());
                                            window.clearInterval(t1);
                                        }
                                    }, 100);
                                }
                                else if (field == "PATIENT_ADDR_City" && !IsEmpty(eval("jsonData." + field))) {
                                    $("#hdnCity").val(eval("jsonData." + field));
                                    var t2 = window.setInterval(function () {
                                        if (onSuccessCity == true) {
                                            $("#ddlCity").ligerComboBox().setValue($("#hdnCity").val());
                                            window.clearInterval(t2);
                                        }
                                    }, 100);
                                }
                                else if (field == "PATIENT_ADDR_District" && !IsEmpty(eval("jsonData." + field))) {
                                    $("#hdnDistrict").val(eval("jsonData." + field));
                                    var t3 = window.setInterval(function () {
                                        if (onSuccessDistrict == true) {
                                            $("#ddlDistrict").ligerComboBox().setValue($("#hdnDistrict").val());
                                            window.clearInterval(t3);
                                        }
                                    }, 100);
                                }
                                else {
                                    ControlSetVal(item.attr("id"), eval("jsonData." + field));
                                }
                            }
                            else {
                                ControlSetVal(item.attr("id"), obj2Timemm(eval("jsonData." + field)));
                            }
                        }
                        else if (type == "radio") {
                            RadioSetVal(exList[i], eval("jsonData." + field), true);
                            $('input:radio[name="' + exList[i] + '"][value=' + eval("jsonData." + field) + ']').click();
                        }
                        else if (type == "checkbox") {
                            CheckBoxSetVal(exList[i], eval("jsonData." + field) + "", true);
                        }
                    }
                    else if (item[0].tagName.toLowerCase() == "select") {
                        ControlSetVal(item.attr("id"), eval("jsonData." + field));
                    }
                }

                $("input[type=button]").removeAttr('disabled');//加载完毕后启用按钮
                $("#txtName").focus();
                $(".lift li:first").click();//重新焦点
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
            waitting2.close();
        },
        error: function () {
            waitting2.close();
            $.ligerDialog.error("程序错误");
        }
    });
}
//pathid 选中的模板ID
function GetPathNameList(pathid) {
    $.ajax({
        url: "/ChestPainCenter/MedicalRecords/GetPathNameList",
        cache: false,
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                var jsonData = $.parseJSON(d.Body);
                $("#DiagnosisDIV").html('');
                for (var i = 0; i < jsonData.length; i++) {
                    var checkedDiagnosisForCss = (parseInt(pathid) == parseInt(jsonData[i].ID)) ? "class='radio_label checked'" : "class='radio_label'";
                    var checkedDiagnosisForInput = (parseInt(pathid) == parseInt(jsonData[i].ID)) ? "checked='checked'" : "";
                    $("#DiagnosisDIV").append("<label " + checkedDiagnosisForCss + "><input type=\"radio\" id=\"PrelDiagnosis" + i + "\" name=\"PrelDiagnosis\" value=\"" + jsonData[i].ID + "\" " + checkedDiagnosisForInput + " >&nbsp;" + jsonData[i].Name + "</label>");
                }
                if (navigator.userAgent.indexOf("Firefox") > 0) { $(":radio,:checkbox").hide(); }
                //动态标签绑定事件
                $("input[type=radio][name=PrelDiagnosis]").click(function () {
                    $("input[type=radio][name=PrelDiagnosis]").removeAttr("checked");
                    $("input[type=radio][name=PrelDiagnosis]").parent().removeClass("checked");
                    $(this).attr("checked", "checked");
                    $(this).prop("checked", true);
                    $(this).parent().addClass("checked");
                    var val = $(this).val();
                    GetDiagnosticPathTemp(val, $("#selPatientList").val());
                });
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}
var dates = '';
function GetDiagnosticPathTemp(pathid, PatientID) {
    if (PatientID == null || PatientID == "") return;
    if (typeof (pathid) == "undefined" || pathid == null || pathid == "") return;
    dates = '';
    $.ajax({
        url: "/ChestPainCenter/MedicalRecords/GetDiagnosticPathTemp?pathId=" + pathid + "&patientId=" + PatientID,
        cache: false,
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                var jsonData = $.parseJSON(d.Body);
                var ScriptStr = "laydate.render({ elem: '#dtDiseaseTime', type: 'datetime'});";
                var value = '';
                var html = "";
                var htm = "";
                var rdoDistinctNameList = "";
                var cbxDistinctNameList = "";
                $("#Customtags").html('');
                for (var i = 0 ; i < jsonData.length; i++) {
                    if (data.indexOf("PatientId") > -1) {
                        value = jsonData[i].ControlContent;
                    }
                    var title = jsonData[i].ControlTitle;
                    var dis = jsonData[i].ControlDescribe;
                    var Id = jsonData[i].ControlId;
                    var name = jsonData[i].ControlName;
                    var IsMust = jsonData[i].IsMust;
                    var must = IsMust == 1 ? '<font style="color:red;">*&nbsp;</font>' : '';
                    var musttag = IsMust == 1 ? ' must="1" ' : '';
                    var tag = jsonData[i].ControlType;
                    if (tag == '0') {
                        var wid = (typeof (jsonData[i].ControlWidth) == "undefined" || jsonData[i].ControlWidth == null || jsonData[i].ControlWidth == 0) ? "130" : jsonData[i].ControlWidth;
                        html += '<tr style="height: 35px;float:left;margin-left:50px;"><td style="text-align:right; ">' + must + title + '：</td><td><input type="text" id="' + Id + '" name="' + name + '" class="l-text" style="width:' + wid + 'px;" value="' + value + '" ' + musttag + ' custom="' + name + '" ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '"><font style="">&nbsp;' + dis + '</font></td></tr>';
                    }
                    if (tag == '1') {
                        var options = jsonData[i].Options;
                        html += '<tr style="height: 35px;float:left;margin-left:50px;"><td style="text-align:right; ">' + must + title + '：</td><td>';
                        if (typeof (options) != "undefined" && options != '') {
                            var myArray = new Array();
                            myArray = options.split("#"); //字符分割 
                            if (myArray.length > 0) {
                                html += '<select id="' + Id + '" name="' + name + '" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '">';
                                var x;
                                for (x in myArray) {
                                    var selected = (!IsEmpty(jsonData[i].ControlContent) && jsonData[i].ControlContent == myArray[x]) ? "selected=\"selected\"" : "";
                                    html += '<option ' + selected + ' value="' + myArray[x] + '">' + myArray[x] + '</option>';
                                }
                                html += '</select>';
                            }
                        }
                        html += '</td></tr>';
                    }
                    if (tag == '2') {
                        var options = jsonData[i].Options;
                        html += '<tr style="height: 35px;float:left;margin-left:50px;"><td style="text-align:right; ">' + must + title + '：</td><td>';
                        if (typeof (options) != "undefined" && options != '') {
                            var myArray = new Array();
                            myArray = options.split("#"); //字符分割 
                            var x;
                            for (x in myArray) {
                                var checked = (!IsEmpty(jsonData[i].ControlContent) && jsonData[i].ControlContent == myArray[x]) ? "checked=checked" : "";
                                html += '<label><input ' + checked + ' type="radio" name="' + name + '" value="' + myArray[x] + '" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '"/>'
                                        + myArray[x] + '&nbsp;&nbsp;</label>';
                                if (rdoDistinctNameList.indexOf(name + ',') < 0)
                                    rdoDistinctNameList += (name + ',');
                            }
                        }
                        html += '</td></tr>';
                    }
                    if (tag == '3') {
                        var options = jsonData[i].Options;
                        html += '<tr style="height: 35px;float:left;margin-left:50px;"><td style="text-align:right; ">' + must + title + '：</td><td>';
                        if (typeof (options) != "undefined" && options != '') {
                            var myArray = new Array();
                            myArray = options.split("#"); //字符分割 
                            var x;
                            for (x in myArray) {
                                var checked = ((!IsEmpty(jsonData[i].ControlContent)) && (jsonData[i].ControlContent == myArray[x] || jsonData[i].ControlContent.indexOf(myArray[x] + ",") >= 0 || jsonData[i].ControlContent.indexOf("," + myArray[x]) >= 0)) ? "checked=checked" : "";
                                html += '<label><input type="checkbox" ' + checked + ' class="l-checkbox" name="' + name + '" value="' + myArray[x] + '" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '"/>' + myArray[x] + '</label>&nbsp;&nbsp;';
                                if (cbxDistinctNameList.indexOf(name + ',') < 0)
                                    cbxDistinctNameList += (name + ',');
                            }
                        }
                        html += '</td></tr>';
                    }
                    if (tag == '4') {
                        var date = jsonData[i].TimeFormart;
                        html += '<tr style="height: 35px;float:left;margin-left:50px;"><td style="text-align:right; ">' + must + title + '：</td><td>';
                        if (typeof (date) != "undefined" && date != '') {
                            switch (date) {
                                case 'yyyy-MM-dd HH:mm:ss'://控件格式为：yyyy-MM-dd HH:mm:ss
                                    dates += (Id + "#");
                                    html += '<input type="text" value="' + obj2Timess(jsonData[i].ControlContent) + '" id="' + Id + '"  name="' + name + '" class="l-text" lay-key="' + new Date().getMilliseconds() + i + '" time="time" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '" >';
                                    break;
                                case '1'://1900-01-01
                                    dates += (Id + "#");
                                    html += '<input type="text" value="' + jsonData[i].ControlContent + '" id="' + Id + '"  name="' + name + '" class="l-text" lay-key="' + new Date().getMilliseconds() + i + '" time="time"  custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '" >';
                                    break;
                                case '2'://1900-01
                                    dates += (Id + "#");
                                    html += '<input type="text" value="' + jsonData[i].ControlContent + '" id="' + Id + '" name="' + name + '" class="l-text" lay-key="' + new Date().getMilliseconds() + i + '" time="time" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '" >';
                                    break;
                                case '3'://1900
                                    dates += (Id + "#");
                                    html += '<input type="text" value="' + jsonData[i].ControlContent + '" id="' + Id + '" name="' + name + '" class="l-text" lay-key="' + new Date().getMilliseconds() + i + '" time="time" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '" >';
                                    break;
                                case '4'://23:00:00
                                    dates += (Id + "#");
                                    html += '<input type="text" value="' + jsonData[i].ControlContent + '" id="' + Id + '" name="' + name + '" class="l-text" lay-key="' + new Date().getMilliseconds() + i + '" time="time" custom="' + name + '"  ControlType="' + jsonData[i].ControlType + '" ControlWidth="' + jsonData[i].ControlWidth + '" ControlTitle="' + title + '" ControlName="' + jsonData[i].ControlName + '"  ControlDescribe="' + dis + '" Options="' + jsonData[i].Options + '" TimeFormart="' + jsonData[i].TimeFormart + '" >';
                                    break;
                            }
                        }
                        html += '</td></tr>';
                    }
                }
                $("#Customtags").append(html);
                $("input[type=radio][checked=checked]").parent().addClass("checked");
                RenderAllTime();
                var rdocbxInputs = "";
                //循环radio的每一组
                if (rdoDistinctNameList.length > 0) {
                    rdoDistinctNameList = rdoDistinctNameList.substring(0, rdoDistinctNameList.length - 1);
                    var rdoDistinctNameListArray = rdoDistinctNameList.split(',');
                    for (var i = 0; i < rdoDistinctNameListArray.length ; i++) {
                        $("input[type=radio][name='" + rdoDistinctNameListArray[i] + "']").parent().addClass("radio_label");
                        if (navigator.userAgent.indexOf("Firefox") > 0) { $(":radio").hide(); }
                        $("input[type=radio][name='" + rdoDistinctNameListArray[i] + "']").click(function () {
                            $("input[type=radio][name='" + $(this).attr('name') + "']").parent().removeClass("checked")
                            $(this).parent().addClass("checked");
                            $("#" + $(this).attr('name')).val($(this).val());
                        })
                        $("input[type=radio][name=" + rdoDistinctNameListArray[i] + "][checked=checked]").parent().addClass("checked");
                        rdocbxInputs += "<input type=\"hidden\" value=\"\" controlType=\"rdo\" id=\"" + rdoDistinctNameListArray[i] + "\"  name=\"" + rdoDistinctNameListArray[i] + "\" >";
                    }
                }
                //循环checkbox的每一组
                if (cbxDistinctNameList.length > 0) {
                    cbxDistinctNameList = cbxDistinctNameList.substring(0, cbxDistinctNameList.length - 1);
                    var cbxDistinctNameListArray = cbxDistinctNameList.split(',');
                    for (var i = 0; i < cbxDistinctNameListArray.length; i++) {
                        $("input[name=" + cbxDistinctNameListArray[i] + "]").parent().addClass("checkbox_label");
                        $("input[type='checkbox'][name='" + cbxDistinctNameListArray[i] + "']").click(function () {
                            $("#" + $(this).attr('name')).val(CheckBoxToArrStr($(this).attr('name')));
                            if ($(this).parent().hasClass("checked"))
                                $(this).parent().removeClass("checked");
                            else
                                $(this).parent().addClass("checked");
                        });
                        $("input[type=checkbox][name=" + cbxDistinctNameListArray[i] + "][checked=checked]").parent().addClass("checked");
                        rdocbxInputs += "<input type=\"hidden\" value=\"\" controlType=\"cbx\" id=\"" + cbxDistinctNameListArray[i] + "\" name=\"" + cbxDistinctNameListArray[i] + "\" >";
                    }
                    if (navigator.userAgent.indexOf("Firefox") > 0) { $(":checkbox").hide(); }
                }
                $("#Customtags").append(rdocbxInputs);
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}
var waitting1;
function GetPatients(patientId) {
    EventGradeDivshowhide();
    waitting1 = $.ligerDialog.waitting('加载中，请稍候...');
    $.ajax({
        url: "/ChestPainCenter/FirstAid/GetPatientList",
        cache: false,
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                var jsonData = $.parseJSON(d.Body);
                $("#selPatientList").html('');
                for (var i = 0; i < jsonData.length; i++) {
                    var age = IsEmpty(jsonData[i].PATIENT_AGE) ? "" : jsonData[i].PATIENT_AGE + "岁";
                    if (defaultPatientId != jsonData[i].PATIENT_ID) {
                        $("#selPatientList").append("<option value=" + jsonData[i].PATIENT_ID + ">" + jsonData[i].PATIENT_NAME + "&nbsp;&nbsp;&nbsp;" + (jsonData[i].PATIENT_SEX == "-1" ? "" : jsonData[i].PATIENT_SEX) + "&nbsp;&nbsp;&nbsp;" + age + "</option>");
                    }
                    else {
                        $("#selPatientList").append("<option select=\"select\" value=" + jsonData[i].PATIENT_ID + ">" + jsonData[i].PATIENT_NAME + "&nbsp;&nbsp;&nbsp;" + (jsonData[i].PATIENT_SEX == "-1" ? "" : jsonData[i].PATIENT_SEX) + "&nbsp;&nbsp;&nbsp;" + age + "</option>");
                    }
                }
                if (defaultPatientId != "") {
                    $("#selPatientList").val(defaultPatientId);
                }
                if (!IsEmpty(patientId)) {
                    $("#selPatientList").val(patientId);
                }
                //加载病历详细
                GetCaseHistory($("#selPatientList").val());
            }
            waitting1.close();
        },
        error: function () {
            waitting1.close();
            $.ligerDialog.error("程序错误");
        }
    });
}
function SetCaseHistory() {
    var checkpass = true;
    $("input[type=text]").each(function () {
        if ($(this).val().indexOf("¤") >= 0 || $(this).val().indexOf("☺") >= 0) {
            checkpass = false;
            return false;
        }
    });
    if (!checkpass) {
        $.ligerDialog.error("输入框包含了非法字符");
        return false;
    }
    var eventGrade = $("input[name='eventGrade']:checked").val();
    if (IsEmpty(eventGrade)) eventGrade = -1;
    var Bypass = $("input[name='Bypass']:checked").val();
    if (IsEmpty(Bypass)) Bypass = -1;
    var Direct = $("input[name='Direct']:checked").val();
    if (IsEmpty(Direct)) Direct = -1;
    var FirstT = $("input[name='FirstT']:checked").val();
    if (IsEmpty(FirstT)) FirstT = -1;
    var LongRange = $("input[name='LongRange']:checked").val();
    if (IsEmpty(LongRange)) LongRange = -1;
    var thrombolysis = $("input[name='thrombolysis']:checked").val();
    if (IsEmpty(thrombolysis)) thrombolysis = -1;
    var thrombolysisAddr = $("input[name='thrombolysisAddr']:checked").val();
    if (IsEmpty(thrombolysisAddr)) thrombolysisAddr = -1;
    var PrelDiagnosis = $("input[name='PrelDiagnosis']:checked").val();//初步诊断
    if (IsEmpty(PrelDiagnosis)) PrelDiagnosis = -1;
    var TransType = $("#selTransType").val();
    if (IsEmpty(TransType)) TransType = -1;
    var CarType = $("input[name='CarType']:checked").val();//出车单位
    if (IsEmpty(CarType)) CarType = -1;
    var Treatment = $("input[name='Treatment']:checked").val();
    if (IsEmpty(Treatment)) Treatment = -1;
    var YzPCI = $("input[name='YzPCI']:checked").val();
    if (IsEmpty(YzPCI)) YzPCI = -1;
    var Zddgs = $("input[name='Zddgs']:checked").val();
    if (IsEmpty(Zddgs)) Zddgs = -1;
    var Sfxyx = $("input[name='Sfxyx']:checked").val();
    if (IsEmpty(Sfxyx)) Sfxyx = -1;
    var Conscious = document.getElementsByName('Conscious');
    var value = new Array();
    for (var i = 0; i < Conscious.length; i++) {
        if (Conscious[i].checked)
            value.push(Conscious[i].value);
    }
    var ConsciousStr = value;
    if (typeof (eventGrade) == "undefined" || eventGrade == null) { eventGrade = 0; }
    if (typeof (Bypass) == "undefined" || Bypass == null) { Bypass = 0; }
    if (typeof (Direct) == "undefined" || Direct == null) { Direct = 0; }

    //获取初步诊断
    var DiagnosticPathContentList = [];
    var Obj = $("input[name=rdoDiagnosticPathId]:checked");
    if (Obj.length != 0) {
        var PatientId = $("#pidd").val();
        var DiagnosticPathId = Obj.val();
        PrelDiagnosis = DiagnosticPathId;
        var nameList = [];
        var controlList = $("[class^=DiagnosticPath" + DiagnosticPathId + "]").find("input[controlType]");
        for (var i = 0; i < controlList.length; i++) {
            var Obj = $(controlList[i]);
            var ControlId = Obj.attr("id");
            var ControlName = Obj.attr("name");
            if (jQuery.inArray(ControlName, nameList) == -1) {
                nameList.push(ControlName);
                var ControlType = Obj.attr("controlType");
                var ControlTitle = $("#" + ControlName.replace(ControlId.substr(0, 3), "lbl")).text();
                var ControlOptions = $("#" + ControlName.replace(ControlId.substr(0, 3), "hdn")).val();
                var ParentIdList = ControlId.split('_');
                var flag = true;
                if (ControlName.indexOf('_') != -1) {
                    if ($("." + ControlName.substring(3, ControlName.lastIndexOf('_'))).css("display") == "none") {
                        flag = false;
                    }
                }
                var ControlContent = "";
                if (flag) {
                    if (ControlType == 2) {
                        ControlContent = $("input[name=" + ControlName + "]:checked").val();
                        ControlContent = ControlContent == undefined ? "" : ControlContent;
                    }
                    else if (ControlType == 3) {
                        $("input[name=" + ControlName + "]:checked").each(function (i) { ControlContent += $(this).val() + "#" });
                        ControlContent = ControlContent.substr(0, ControlContent.length - 1);
                    }
                    else {
                        ControlContent = Obj.val();
                    }
                }
                DiagnosticPathContentList.push({ DiagnosticPathId: DiagnosticPathId, PatientId: PatientId, ControlId: ControlId, ControlName: ControlName, ControlType: ControlType, ControlTitle: ControlTitle, ControlContent: ControlContent, Options: ControlOptions });
            }
        }
    }

    $("#ContentList").val(JSON.stringify(DiagnosticPathContentList));

    //院前心电图
    var Image1_ADD = "";
    $(".imgUpload1").each(function () {
        Image1_ADD += $(this).attr("src") + "|";
    });
    Image1_ADD = Image1_ADD.substr(0, Image1_ADD.length - 1);

    //院内心电图
    var Image_ADD = "";
    $(".imgUpload3").each(function () {
        Image_ADD += $(this).attr("src") + "|";
    });
    Image_ADD = Image_ADD.substr(0, Image_ADD.length - 1);

    //心超图
    var Radiology_HeartSuper_ADD = "";
    $(".imgUpload4").each(function () {
        Radiology_HeartSuper_ADD += $(this).attr("src") + "|";
    });
    Radiology_HeartSuper_ADD = Radiology_HeartSuper_ADD.substr(0, Radiology_HeartSuper_ADD.length - 1);

    var RequestURl = "/ChestPainCenter/MedicalRecords/SetCaseHistory?eventGrade=" + eventGrade
        + "&Bypass=" + Bypass
        + "&Direct=" + Direct
        + "&FirstT=" + FirstT
        + "&LongRange=" + LongRange
        + "&thrombolysis=" + thrombolysis
        + "&thrombolysisAddr=" + thrombolysisAddr
        + "&PrelDiagnosis=" + PrelDiagnosis
        + "&Treatment=" + Treatment
        + "&YzPCI=" + YzPCI
        + "&Zddgs=" + Zddgs
        + "&Sfxyx=" + Sfxyx
        + "&Conscious=" + ConsciousStr
        + "&TransType=" + TransType
        + "&Image1_ADD=" + Image1_ADD
        + "&Image_ADD=" + Image_ADD
        + "&Radiology_HeartSuper_ADD=" + Radiology_HeartSuper_ADD;

    if (eventGrade == 0 || eventGrade == 1) {
        if (eventGrade == 0) {
            RequestURl += "&CarType=" + CarType;
        }
    }
    $.ajax({
        type: "POST",
        url: RequestURl,
        cache: false,
        dataType: "text",
        data: $("#formSubmit").serialize(),
        success: function (data) {
            $.ligerDialog.success(data);
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}
function RenderAllTime() {
    $('*[time]').each(function () {
        var ids = $(this).attr('id');
        ids = '#' + ids;
        laydate.render({ elem: ids, type: 'datetime' });
    });
}
function Goto() {
    if ($("#selPatientList").val() == "") return;
    var url = "/ChestPainCenter/Pathway/Index?id=" + $("#selPatientList").val() + '&name=' + escape(Lname) + '&sex=' + escape(Lsex) + '&age=' + Lage + '&dis=' + escape(Ldis);
    window.parent.top.tab.addTabItem({ tabid: "time" + $("#selPatientList").val(), text: "时间轴-" + $("#txtName").val(), url: url });
}
function Print() {
    if ($("#txtID").val() == "") return;
    window.parent.top.tab.addTabItem({ tabid: "print" + $("#txtID").val(), text: "病历-" + $("#txtName").val(), url: "/ChestPainCenter/MedicalRecords/EventPrint?pid=" + $("#txtID").val() });
}
function PrintPlus() {
    if ($("#txtID").val() == "") return;
    window.parent.top.tab.addTabItem({ tabid: "print" + $("#txtID").val(), text: "病历-" + $("#txtName").val(), url: "/ChestPainCenter/MedicalRecords/EventPrintPlus?pid=" + $("#txtID").val() });
}
//来院方式的子项显示隐藏
function ChangeWayOfComing(Comtype) {
    if (typeof (Comtype) == "undefined" || Comtype == null || Comtype == "") return;
    Comtype = parseInt(Comtype);
    switch (Comtype) {
        case 1:
            $("*[tr0]").show();
            $("*[tr1]").show();
            $("*[tr2]").css("display", "none");
            $("*[tr3]").css("display", "none");
            $("*[tr4]").css("display", "none");
            $("*[tr5]").show();
            $("*[tdRound]").text("患者绕行急诊：");
            break;
        case 2:
            $("*[tr0]").show();
            $("*[tr1]").css("display", "none");
            $("*[tr2]").show();
            $("*[tr3]").css("display", "none");
            $("*[tr4]").css("display", "none");
            $("*[tr5]").show();
            $("*[tdRound]").text("患者绕行急诊：");
            break;
        case 3:
            $("*[tr0]").css("display", "none");
            $("*[tr1]").css("display", "none");
            $("*[tr2]").css("display", "none");
            $("*[tr3]").css("display", "none");
            $("*[tr4]").css("display", "none");
            $("*[tr5]").show();
            $("*[tdRound]").text("患者绕行CCU：");
            break;
        case 4:
            $("*[tr0]").css("display", "none");
            $("*[tr1]").css("display", "none");
            $("*[tr2]").css("display", "none");
            $("*[tr3]").show();
            $("#txtDiseaseDep").hide();
            $("*[tr4]").css("display", "none");
            $("*[tr5]").css("display", "none");
            break;
        default:
            $.ligerDialog.error("不支持的来院方式" + Comtype);
            break;
    }
    position();
}

//心电 在页面加载或者值改变的时候均需要调用
function LongRangeDivshowhide() {
    if ($("input[name='LongRange']:checked").val() == 1) {
        $("#divLongRange1").show();
        $("#divLongRange2").show();
    } else {
        $("#divLongRange1").hide();
        $("#divLongRange2").hide();
    }
}
//绕行 在页面加载或者值改变的时候均需要调用
function BypassDivshowhide() {
    if ($("input[name='Bypass']:checked").val() == 1) {
        $("#divBypass1").show();
        $("#divBypass2").show();
    } else {
        $("#divBypass1").hide();
        $("#divBypass2").hide();
    }
}
//来院方式
function EventGradeDivshowhide() {
    var comtype = $("input[name=eventGrade]:checked").val();
    ChangeWayOfComing(comtype);
}
//图片处理
function ZipImage(src, callback) {
    // 参数，最大高度 
    var MAX_HEIGHT = 600;
    var image = new Image();
    image.onload = function () {
        var canvas = document.getElementById("canvas");
        if (image.height > MAX_HEIGHT) {
            image.width *= MAX_HEIGHT / image.height;
            image.height = MAX_HEIGHT;
        }
        var ctx = canvas.getContext("2d");
        // canvas清屏 
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        // 重置canvas宽高 
        canvas.width = image.width;
        canvas.height = image.height;
        // 将图像绘制到canvas上 
        ctx.drawImage(image, 0, 0, image.width, image.height);
        var data = canvas.toDataURL("image/png");
        callback(data);
    };
    image.src = src;
};
function CheckedFromVal(checkboxId, val) {
    $("#" + checkboxId).removeAttr("checked");
    var reg_num = /^\d+$/;
    if (!IsEmpty(val) && reg_num.test(val) && parseInt(val) > 0) {
        $("#" + checkboxId).attr("checked", 'checked');
        $("#" + checkboxId).prop("checked", 'checked');
        $("#" + checkboxId).parent().addClass("checked");
    } else {
        $("#" + checkboxId).removeAttr("checked");
        $("#" + checkboxId).parent().removeClass("checked");
    }
}
$(document).ready(function () {
    $("#txtmgAspirin").blur(function () {
        CheckedFromVal("cbxisAspirin", $(this).val());
    })
    $("#txtmgTicagrelor").blur(function () {
        CheckedFromVal("cbxisTicagrelor", $(this).val());
    })
    $("#txtmgClopidogrel").blur(function () {
        CheckedFromVal("cbxisClopidogrel", $(this).val());
    })
    $("#txtmgRosuvastatin").blur(function () {
        CheckedFromVal("cbxisRosuvastatin", $(this).val());
    })
    $("#txtmgAtorvastatin").blur(function () {
        CheckedFromVal("cbxisAtorvastatin", $(this).val());
    })
    $("#txtmgHeparin").blur(function () {
        CheckedFromVal("cbxisHeparin", $(this).val());
    })
    $("#txtmgAspirin2").blur(function () {
        CheckedFromVal("cbxisAspirin2", $(this).val());
    })
    $("#txtmgTicagrelor2").blur(function () {
        CheckedFromVal("cbxisTicagrelor2", $(this).val());
    })
    $("#txtmgClopidogrel2").blur(function () {
        CheckedFromVal("cbxisClopidogrel2", $(this).val());
    })
    $("#txtmgRosuvastatin2").blur(function () {
        CheckedFromVal("cbxisRosuvastatin2", $(this).val());
    })
    $("#txtmgAtorvastatin2").blur(function () {
        CheckedFromVal("cbxisAtorvastatin2", $(this).val());
    })
    $("#txtEnzyme").blur(function () {
        CheckedFromVal("cbxisEnzyme", $(this).val());
    })
    $("#txtUrokinase").blur(function () {
        CheckedFromVal("cbxisUrokinase", $(this).val());
    })
    $("#txtAntiplatelet_Aspirin").blur(function () {
        CheckedFromVal("chkisAntiplatelet_Aspirin", $(this).val());
    })
    $("#txtAntiplatelet_Ticagrelor").blur(function () {
        CheckedFromVal("chkisAntiplatelet_Ticagrelor", $(this).val());
    })
    $("#txtAntiplatelet_Clopidogrel").blur(function () {
        CheckedFromVal("chkisAntiplatelet_Clopidogrel", $(this).val());
    })

    $("#cbxisAspirin").click(function () {
        if ($("#cbxisAspirin").prop("checked") == false) {
            $("#cbxisAspirin").attr("checked", "checked");
            $("#cbxisAspirin").prop("checked", true);
        }
        $("#txtmgAspirin").select();
    })
    $("#cbxisTicagrelor").click(function () {
        if ($("#cbxisTicagrelor").prop("checked") == false) {
            $("#cbxisTicagrelor").attr("checked", "checked");
            $("#cbxisTicagrelor").prop("checked", true);
        }
        $("#txtmgTicagrelor").select();
    })
    $("#cbxisClopidogrel").click(function () {
        if ($("#cbxisClopidogrel").prop("checked") == false) {
            $("#cbxisClopidogrel").attr("checked", "checked");
            $("#cbxisClopidogrel").prop("checked", true);
        }
        $("#txtmgClopidogrel").select();
    })
    $("#cbxisHeparin").click(function () {
        if ($("#cbxisHeparin").prop("checked") == false) {
            $("#cbxisHeparin").attr("checked", "checked");
            $("#cbxisHeparin").prop("checked", true);
        }
        $("#txtmgHeparin").select();
    });
    $("#cbxisRosuvastatin").click(function () {
        if ($("#cbxisRosuvastatin").prop("checked") == false) {
            $("#cbxisRosuvastatin").attr("checked", "checked");
            $("#cbxisRosuvastatin").prop("checked", true);
        }
        $("#txtmgRosuvastatin").select();
    })
    $("#cbxisAtorvastatin").click(function () {
        if ($("#cbxisAtorvastatin").prop("checked") == false) {
            $("#cbxisAtorvastatin").attr("checked", "checked");
            $("#cbxisAtorvastatin").prop("checked", true);
        }
        $("#txtmgAtorvastatin").select();
    })
    $("#cbxisAspirin2").click(function () {
        if ($("#cbxisAspirin2").prop("checked") == false) {
            $("#cbxisAspirin2").attr("checked", "checked");
            $("#cbxisAspirin2").prop("checked", true);
        }
        $("#txtmgAspirin2").select();
    })
    $("#cbxisTicagrelor2").click(function () {
        if ($("#cbxisTicagrelor2").prop("checked") == false) {
            $("#cbxisTicagrelor2").attr("checked", "checked");
            $("#cbxisTicagrelor2").prop("checked", true);
        }
        $("#txtmgTicagrelor2").select();
    })
    $("#cbxisClopidogrel2").click(function () {
        if ($("#cbxisClopidogrel2").prop("checked") == false) {
            $("#cbxisClopidogrel2").attr("checked", "checked");
            $("#cbxisClopidogrel2").prop("checked", true);
        }
        $("#txtmgClopidogrel2").select();
    })
    $("#cbxisRosuvastatin2").click(function () {
        if ($("#cbxisRosuvastatin2").prop("checked") == false) {
            $("#cbxisRosuvastatin2").attr("checked", "checked");
            $("#cbxisRosuvastatin2").prop("checked", true);
        }
        $("#txtmgRosuvastatin2").select();
    })
    $("#cbxisAtorvastatin2").click(function () {
        if ($("#cbxisAtorvastatin2").prop("checked") == false) {
            $("#cbxisAtorvastatin2").attr("checked", "checked");
            $("#cbxisAtorvastatin2").prop("checked", true);
        }
        $("#txtmgAtorvastatin2").select();
    })
    $("#cbxisEnzyme").click(function () {
        if ($("#cbxisEnzyme").prop("checked") == false) {
            $("#cbxisEnzyme").attr("checked", "checked");
            $("#cbxisEnzyme").prop("checked", true);
        }
        $("#txtEnzyme").select();
    })
    $("#cbxisUrokinase").click(function () {
        if ($("#cbxisUrokinase").prop("checked") == false) {
            $("#cbxisUrokinase").attr("checked", "checked");
            $("#cbxisUrokinase").prop("checked", true);
        }
        $("#txtUrokinase").select();
    })
    $("#chkisAntiplatelet_Aspirin").click(function () {
        if ($("#chkisAntiplatelet_Aspirin").prop("checked") == false) {
            $("#chkisAntiplatelet_Aspirin").attr("checked", "checked");
            $("#chkisAntiplatelet_Aspirin").prop("checked", true);
        }
        $("#txtAntiplatelet_Aspirin").select();
    });
    $("#chkisAntiplatelet_Ticagrelor").click(function () {
        if ($("#chkisAntiplatelet_Ticagrelor").prop("checked") == false) {
            $("#chkisAntiplatelet_Ticagrelor").attr("checked", "checked");
            $("#chkisAntiplatelet_Ticagrelor").prop("checked", true);
        }
        $("#txtAntiplatelet_Ticagrelor").select();
    });
    $("#chkisAntiplatelet_Clopidogrel").click(function () {
        if ($("#chkisAntiplatelet_Clopidogrel").prop("checked") == false) {
            $("#chkisAntiplatelet_Clopidogrel").attr("checked", "checked");
            $("#chkisAntiplatelet_Clopidogrel").prop("checked", true);
        }
        $("#txtAntiplatelet_Clopidogrel").select();
    });


    $(":text[typeof=number]").keyup(function () {
        var c = $(this);
        if (/[^\d]/.test(c.val())) {
            var num = c.val().replace(/[^\d]/g, '');
            $(this).val(num == "" ? "" : parseInt(num));
        }
    })
    $("#btnGiveUp").click(function () {
        if ($("#txtID").val() == "") return;
        $.ligerDialog.confirm('确定删除该患者吗', function (yes) {
            if (yes) {
                var url = "/ChestPainCenter/PatientList/GiveUp";
                $.get(url, {
                    rnd: new Date().getMilliseconds(),
                    patientId: $("#txtID").val()
                }, function (data, textStatus) {
                    if (textStatus == "success") {
                        var d = $.parseJSON(data);
                        if (d.Result == 1) {
                            $.ligerDialog.success("删除成功");
                            window.location.reload(true);
                        }
                        else if (d.Result == 0) {
                            $.ligerDialog.error(d.Body);
                        }
                        else {
                            $.ligerDialog.error("程序错误");
                        }
                    }
                })
            }
        });
    })
    $("#btnRefresh").click(function () {
        var patientId = $("#txtID").val();
        GetPatients(patientId);
    })
})
$(document).ready(function () {
    $("#txtXnkDoc").ligerComboBox({
        url: "/ChestPainCenter/MedicalRecords/GetDropDoctorList",
        parms: { key: $(this).val(), list: encodeURI($("#hdnDoctorList").val()) },
        valueField: 'Id',
        textField: 'Name',
        selectBoxWidth: 130,
        autocomplete: true,
        keySupport: true,
        width: 130
    });
    $("#txtNurse,#txtMedical_Name").ligerComboBox({
        url: "/ChestPainCenter/MedicalRecords/GetDropDocNurList",
        parms: { key: $(this).val(), list: encodeURI($("#hdnDocNurList").val()) },
        valueField: 'Id',
        textField: 'Name',
        selectBoxWidth: 130,
        autocomplete: true,
        keySupport: true,
        width: 130
    });
    $("#txtDiseaseDep,#txtMeetRoomName").ligerComboBox({
        url: "/ChestPainCenter/MedicalRecords/GetDropRoomList",
        parms: { key: $(this).val(), list: encodeURI($("#hdnRoomList").val()) },
        valueField: 'Name',
        textField: 'Name',
        selectBoxWidth: 130,
        autocomplete: true,
        keySupport: true,
        width: 130
    });
});

//是否死亡
function showDieInfo() {
    var val = $("input[name=die_Bool]:checked").val();
    if (val == 1) {
        $(".divDie_Bool").show();
    }
    else {
        $(".divDie_Bool").hide();
    }
    position();
}

//设置初步诊断
function setDiagnosticPath(patientId) {
    $("[class^=DiagnosticPath]").hide();
    $.ajax({
        url: "/ChestPainCenter/MedicalRecords/GetPatientIDPrimaryDiagnosis",
        data: { patientId: patientId },
        cache: false,
        async: false,
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                $("input[name=rdoDiagnosticPathId][value=" + $("#DiagnosticPathId").val() + "]").click();
                var jsonData = $.parseJSON(d.Body);
                for (var i = 0; i < jsonData.length; i++) {
                    var id = jsonData[i].ControlId;
                    var name = jsonData[i].ControlName;
                    var type = jsonData[i].ControlType;
                    var title = jsonData[i].ControlTitle;
                    var content = jsonData[i].ControlContent;

                    switch (type) {
                        case 0: //文本框
                            ControlSetVal(id, content);
                            break;
                        case 1: //下拉框
                            break;
                        case 2: //单选框
                            $("input[name=" + name + "][value=" + content + "]").click();
                            break;
                        case 3: //复选框
                            var list = content.split('#');
                            for (var ii = 0; ii < list.length; ii++) {
                                $("input[name=" + name + "][value=" + list[ii] + "]").click();
                            }
                            break;
                        case 4: //时间框
                            ControlSetVal(id, obj2Timemm(content));
                            break;
                    }
                }
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}

//初步诊断控件显示
function setDiagnosticPathDisplay() {
    $("[class^=DiagnosticPath]").hide();
    $("input[name=rdoDiagnosticPathId]").click(function () {
        var className = "DiagnosticPath" + $(this).val();
        $("[class^=DiagnosticPath]").hide();
        $("[class=" + className + "]").show();
        if ($("[class=" + className + "]").find(":radio").length > 0) {
            if ($._data($("[class=" + className + "]").find(":radio")[0], "events")["click"].length == 2) {
                $("[class=" + className + "]").find(":radio:checked").click();
                $("[class=" + className + "]").find(":checkbox:checked").click().click();
            }
            else {
                $("[class=" + className + "]").find(":radio").click(function () {
                    var childClassName = $(this).attr("name").replace("rdo", "") + $(this).val();
                    $("[class^=" + childClassName.substring(0, childClassName.length - 1)).hide();
                    $("[class=" + childClassName + "]").show();
                    position();
                });

                $("[class=" + className + "]").find(":checkbox").click(function () {
                    var childClassName = $(this).attr("name").replace("chk", "") + $(this).val();
                    if ($(this).is(":checked")) {
                        $("[class=" + childClassName + "]").show();
                    }
                    else {
                        $("[class=" + childClassName + "]").hide();
                    }
                    position();
                });
            }
        }
        position();
    });
}

//设置初步诊断时间
function setDiagnosticPathLayDate() {
    $("input[controlType=4]").each(function () {
        var option = {};
        option.elem = $(this)[0];
        option.type = 'datetime';
        var format = $(this).attr('data-dateformat');
        if (format != '' && format != undefined) option.format = format;
        laydate.render(option);
    });
}

//获取导航列表
function getNavList() {
    $.ajax({
        url: "/ChestPainCenter/MedicalRecords/getNavList?ram" + Math.random(),
        type: "GET",
        data: {},
        async: false,
        success: function (data) {
            var r = $.parseJSON(data);
            if (r.Result == 1) {
                $("#navlist").html('');
                var list = $.parseJSON(r.Body);;
                for (var i = 0; i < list.length; i++) {
                    $("#navlist").append("<li>" + list[i].Title_Name + "</li>");
                    $(":header").eq(i).text(list[i].Title_Name);
                }
            }
            else if (r.Result == 0) {
                $.ligerDialog.error(r.Body.T_Content);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        }
    });
}

//上传图片
function upload(id, buttonText, index) {
    $("#" + id).uploadify({
        swf: '/Scripts/uploadify/uploadify.swf',
        uploader: '/Image/UploadFile',
        formData: {},
        height: 60,
        width: 60,
        multi: false, //设置为true时可以上传多个文件
        auto: true,
        buttonText: buttonText,
        buttonCursor: 'hand',
        buttonClass: 'uploadFile_button',
        fileTypeExts: '*.gif; *.jpg; *.png; *.jpeg', //文件后缀限制
        fileSizeLimit: '2MB',
        fileTypeDesc: 'Image Files',
        queueSizeLimit: 10,
        uploadLimit: 10, //最大上传文件数量
        removeTimeout: 3,
        onUploadSuccess: function (file, data, response) { //上传成功
            var photo = $("<div class=\"photo" + index + "\" style=\"float:left;margin-left:10px;margin-top:10px;text-align:center;\"><img class=\"imgUpload" + index + "\" src=\"" + thisHostWithHttp() + data + "\" style=\"height:60px;width:60px;\" onclick=\"window.open('" + thisHostWithHttp() + data + "');\" /><p style=\"color:#808080;cursor:default;\" onclick=\"delFile(this,'" + data + "'," + index + ")\">删除</p></div>");
            $("#tdPhoto" + index).append(photo);
            $(".photo" + index).eq(0).css('margin-left', 0);
            if ($(".photo" + index).length >= 8) {
                $("#btnAddPic" + index).hide();
            }
        },
        onFallback: function () {
            $.ligerDialog.error("未检测到兼容版本的Flash！");
        },
        onSelectError: function (file, errorCode, errorMsg) { //选择失败
            switch (errorCode) {
                case -100:
                    $.ligerDialog.error("上传的文件数量已经超出系统限制的" + $('#uploadFile').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    $.ligerDialog.error("文件 [" + file.name + "] 大小超出系统限制的" + $('#uploadFile').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    $.ligerDialog.error("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    $.ligerDialog.error("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        }
    });
}

//删除图片
function delFile(obj, path, index) {
    $.ajax({
        url: "/Image/DelFile?path=" + path,
        async: false,
        type: "GET",
        cache: false,
        success: function (r) {
            var r = $.parseJSON(r);
            if (r.Result == 1) {
                $(obj).parent().remove();
                $(".photo" + index).eq(0).css('margin-left', 0);
                if ($(".photo" + index).length < 8) {
                    $("#btnAddPic" + index).show();
                }
            }
            else if (r.Result == 0) {
                $.ligerDialog.error(r.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}